package com.itheima.d06_api_object;

import java.util.Objects;

/**
 * 猪类：
 */
public class Pig implements Cloneable{

    private String name;
    private int age;
    private String sex;

    public Pig() {
    }

    public Pig(String name, int age, String sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }


    @Override
    protected Object clone() throws CloneNotSupportedException {
        //克隆操作，由父类来实现，子类需要调用父类的clone方法
        return super.clone();
    }

//    @Override
//    public String toString() {
//        return "Pig{" +
//                "name='" + name + '\'' +
//                ", age=" + age +
//                ", sex='" + sex + '\'' +
//                '}';
//    }


    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;
        Pig pig = (Pig) o;
        return age == pig.age && Objects.equals(name, pig.name) && Objects.equals(sex, pig.sex);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age, sex);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }
}
